<?php

class GlobalView {
	public $tpl;
	
	public function __construct() {
		$this->tpl = xine::factory('xineForumTemplater');
	}
	
	public function link ($title, $link, $ext='') {
		return '<a href="'.xine::$config['siteUrl'].$link.'" '.$ext.'>'.$title.'</a>';
	}
	
	public function showHeader () {
		if(xine::$ACS->isAuth()) {
			$this->tpl->assign(array('auth_link' => self::link(xine::$user['name'], 'members/'.xine::$user['name'])));
		} else {
			$this->tpl->assign(array('auth_link' => self::link('Войти', 'signin', 'id="auth_panel"')));
		}
		
		$this->tpl->header(xine::$config['theme']);
	}
	
	public function showFooter () {
		$this->tpl->footer();
	}
	
	public function getDate ($timestamp) {
		$replaces = array(
			'01' => 'Январь',
			'02' => 'Февраль',
			'03' => 'Март',
			'04' => 'Апрель',
			'05' => 'Май',
			'06' => 'Июнь',
			'07' => 'Июоь',
			'08' => 'Август',
			'09' => 'Сентябрь',
			'10' => 'Октябрь',
			'11' => 'Ноябрь',
			'12' => 'Декабрь'
		);
		
		$month = $replaces[date("m", $timestamp)];
		
		if(date("d", $timestamp) == date("d", time())) {
			return date("H:i", $timestamp);
		} else {
			return $month.' '.date("j", $timestamp);
		}
	}
	
	public function getReply ($d, $s='') {
		return '
	<li class="Item Comment '.($d['discussion_starter']==0?'':'FirstComment').' Mine" id="Reply_'.$d['id'].'" style="'.$s.'">
		<div class="Comment">
			<div class="Meta">
				<span class="Author"><a href="'.xine::$config['siteUrl'].'members/'.$d['author'].'">'.$d['author'].'</a></span>
				<span class="DateCreated">'.$this->getDate($d['time']).'</span>
				<span><a href="'.xine::$config['siteUrl'].'edit/delete/'.$d['id'].'" id="Delete">Удалить</a></span>
			</div>
			<div class="Message">
				<p>'.$d['text'].'</p>
			</div>
		</div>
	</li>
		';
	}
}